<template>
  <view class="container">
    <view class="main">
      <view
        v-if="questionList.length===0"
        class="empty"
      >
        <view class="img">
          <image src="http://jiales.gz-yami.com/question.png" />
        </view>
        <view class="txt">
          您还没有问题
        </view>
      </view>
      <radio-group class="radio-group">
        <block
          v-for="(item, index) in questionList"
          :key="index"
        >
          <view class="question">
            <view
              class="personal"
              @tap="selQuestionToOrder(item)"
            >
              <view class="info-tit">
                <text class="name">
                  {{ item.receiver }}
                </text>
                <text class="tel">
                  {{ item.mobile }}
                </text>
                <image
                  src="@/static/images/icon/revise.png"
                  :data-questionid="item.questionId"
                  @tap.stop="toEditquestion"
                />
              </view>
              <view class="question">
                <text class="question-get">
                  {{ item.province }}{{ item.city }}{{ item.area }}{{ item.question }}
                </text>
              </view>
            </view>
      
          </view>
        </block>
      </radio-group>
    </view>
    <view
      class="footer"
      @tap="onAddQuestion"
    >
      <text>新增问题</text>
    </view>
  </view>
</template>

<script setup>
const order = ref(-1)
onLoad((option) => {
  if (option.order) {
    order.value = option.order
  }
})

const questionList = ref([])
/**
 * 加载问题列表
 */
onShow(() => {
  onGetList()
})

/**
 * 获取收获列表接口
 */
const onGetList = () => {
  uni.showLoading()
  http.request({
    url: '/p/question/list',
    method: 'GET'
  })
    .then(({ data }) => {
      questionList.value = data
      uni.hideLoading()
    })
}

/**
 * 新增问题
 */
const onAddQuestion = () => {
  uni.navigateTo({
    url: '/pages/other/questionEdit'
  })
}

/**
 * 修改问题
 */
const toEditquestion = (e) => {
  const questionId = e.currentTarget.dataset.questionid
  uni.navigateTo({
    url: '/pages/other/questionEdit?questionId=' + questionId
  })
}

/**
 * 选择问题 跳转回提交订单页
 */
const selQuestionToOrder = (item) => {
  if (order.value == 0) {
    const pages = getCurrentPages() // 当前页面
    const prevPage = pages[pages.length - 2] // 上一页面
    prevPage.item = item // 直接给上一页面赋值
    prevPage.selquestion = 'yes'
    // 返回
    uni.navigateBack({
      delta: 1
    })
  }
}
</script>
fid
<style scoped lang="scss">
@use './questionList.scss';
</style>
